package gui.utils;

import gui.IHM;

import java.awt.Point;
import java.awt.Window;

import javax.swing.SwingUtilities;

/**
 * @author Charles Perin
 * 29 mars 2011
 * LIMSI - INRIA Rennes
 * charles.perin@free.fr
 *
 */
public class SwingUtilitiesPerso {

	public static Window getTopWindowContaining(IHM ihm, int x,int y) {

		Window[] windows = Window.getWindows();
		for(int i = 0; i < windows.length; i++) {
			Point localPoint = SwingUtilities.convertPoint(ihm, new Point(x,y), windows[i]);
			if(windows[i].getFocusOwner() != null && windows[i].contains(localPoint)) {
				return windows[i];
			}
		}
		if(windows.length > 0) {
			return windows[0];
		}
		return null;
	}
}
